<?php

include_once("../controller/permissoes_controller_class.php");
include_once("../controller/opcoes_sistema_controller_class.php");
include_once("../controller/nivel_controller_class.php");

$nivel = $_POST['niv'];
//$nivel = 5;

$objOpc = new OpcoesSistemaController();
$listOpc = $objOpc->selecionar();

$objPermissoes = new PermissoesController();

$list = $objPermissoes->selecionarPorNivel($nivel);

$array[] = array(
    'id' => 0,
    'descricao' => 'Cadastre Permissões'
);
$i = 0;
foreach ($listOpc as $opc) {
    $checked = "";
    foreach ($list as $li) {
        if ($opc->getId() == $li->getOpcoes()) {
            $checked = "checked";
            break;
        }
    }

    $array[$i++] = array(
        'id' => $opc->getId(),
        'descricao' => $opc->getDescricao(),
        'checked' => $checked,
    );
}


echo json_encode($array);
